package framework.web;

import framework.pojo.Item;
import framework.pojo.Page;
import framework.service.ItemService;
import framework.service.impl.ItemServiceImp;
import framework.utils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RecordItemServlet extends BaseServlet{
    private ItemService itemService = new ItemServiceImp();

    protected void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1 获取请求的参数 pageNo 和 pageSize
        int pageNo = WebUtils.parseInt(req.getParameter("pageNo"), 1);
        int pageSize = WebUtils.parseInt(req.getParameter("pageSize"), Page.PAGE_SIZE);
        //2 调用BookService.page(pageNo，pageSize)：Page对象
        Page<Item> page = itemService.page(pageNo, pageSize);

        page.setUrl("record/ItemServlet?action=page");


        //3 保存Page对象到Request域中
        req.setAttribute("page", page);
        //4 请求转发

        req.getRequestDispatcher("/page/user/record.jsp").forward(req, resp);
    }
}
